<template>
  <div class="cusha">
    <div v-if="!inline" class="content_title" style="cursor: pointer" @click="showDialogTech">
      <span class="content_text">粗纱</span>
      <img class="content_img" src="@/assets/img/chart/cusha.png" alt="" srcset="" />
    </div>
    <div class="cusha_body" :class="{ 'cusha-inline': inline }">
      <div v-for="(item, index) in cushaData.cushaDataRow1Data" :key="index + 'a'" class="cusha_item">
        <div v-if="index == 0">
          <div class="dongli2" @click="clickHandleDl('cusha_' + index)">
            <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
          </div>
        </div>
        <div @click="clickHandle(item)">
          <cusha :data="item"></cusha>
        </div>
        <div v-if="index == cushaData.cushaDataRow1Data.length - 1">
          <div class="dongli1" @click="clickHandleDl('cusha_' + index)">
            <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
          </div>
        </div>
      </div>
    </div>
    <!-- 粗纱弹窗控件 -->
    <cushaDialog v-if="showModal" :defaultData="data1" ref="cushaDialog"></cushaDialog>
    <!-- 动力柜弹窗控件 -->
    <dongliDialog v-if="showDongliModal" ref="dongliDialog"></dongliDialog>
    <!-- 粗纱工艺详情 -->
    <cusha-dialog-tech v-if="techShow" ref="cushaDialogTech"></cusha-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_dongli/index'
import cushaDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_cusha/index'
import cusha from '@/views/monitorCenter/workChart/components/qcs/cusha'
import COMMON from '@/utils/common'
import dongLiMenu from '@/assets/data/dongli.json'
import dongliItem from '@/assets/data/dongliItem.json'
export default {
  name: 'CuSha',
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    dongliDialog,
    cusha,
    cushaDialog
  },
  data() {
    return {
      cushaData: {
        // 1-14
        cushaDataRow1Data: [],
        // 15-16
        cushaDataRow2Data: [],
        dongLiMenu: {},
        dongLiItem: {}
      },
      techShow: false,
      showModal: false,
      showDongliModal: false,
      data1: {}
    }
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.cushaDialogTech = require('@/views/monitorCenter/workChart/components/qcs/dialogBig/dialog_cusha_tech/index').default
  },
  created() {
    this.dongLiMenu = dongLiMenu
    this.dongLiItem = dongliItem
  },
  computed: {
    txcsomlGroupState() {
      let result
      if (this.$store.state.socketData.length != 0) {
        result = this.$store.state.socketData.filter(item => item.workshop == this.$store.state.workshopNo)
        result = result[0].dsDeviceRealTimeStatusListRove
      }
      return result
    }
  },
  watch: {
    txcsomlGroupState: {
      immediate: true,
      handler(val) {
        if (val) {
          this.cushaData.cushaDataRow1Data = COMMON.devSnFilter(val, 1, 16)
        }
      }
    }
  },
  methods: {
    closeHandle() {
      this.showModal = false
      this.showDongliModal = false
    },
    clickHandle(item) {
      this.data1 = item
      this.data1.classes = this.$store.state.workshopData.shiftPreSpinTxt
      this.showModal = true
    },
    clickHandleDl(item) {
      this.showDongliModal = true
      var dialogData = this.dongLiItem[`${item}_${this.$store.state.workshopNo}`]
      this.$nextTick(() => {
        this.$refs.dongliDialog.showDialog(dialogData)
      })
    },
    showDialogTech() {
      this.techShow = true
    },
    closeDialogTech() {
      this.techShow = false
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/workshop.less';
</style>
